package cn.mldn.mldncloud.dao;

import cn.mldn.mldncloud.po.Orders;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface IOrdersDAO extends JpaRepository<Orders,Long> { 	// 包含有全部的基础Crud支持
	List<Orders> findByrefectoryId(String refectoryId);
	@Query(value = "SELECT * FROM orders WHERE TO_DAYS( NOW( ) ) - TO_DAYS(create_time ) <= 0 and refectory_id = ?1", nativeQuery = true)
	List<Orders> findTodayOrders(String refectoryId);
	@Query(value="SELECT COUNT(*) from orders where TO_DAYS( NOW( ) ) - TO_DAYS(create_time ) <= 0 and refectory_id = ?1" , nativeQuery = true)
	int findTodayOrdersCount(String refectoryId);
	@Query(value="SELECT COUNT(*) from orders where refectory_id = ?1" , nativeQuery = true)
	int findOrdersCount(String refectoryId);
	@Query(value = "SELECT * FROM orders WHERE TO_DAYS( NOW( ) ) - TO_DAYS(create_time ) <= 0 and refectory_id = ?1 limit ?2 , ?3", nativeQuery = true)
	List<Orders> findTodayOrdersPage(String refectoryId,int currentIndex,int size);
	@Query(value = "SELECT * FROM orders WHERE refectory_id = ?1 limit ?2 , ?3", nativeQuery = true)
	List<Orders> findOrdersPage(String refectoryId,int currentIndex,int size);
		
}
